{% extends 'users/usercenter-base.html' %}
{% load staticfiles %}

{% block title %}我的收藏- 谷粒教育网{% endblock %}

{% block breach %}我的收藏{% endblock %}

{% block reght %}
    <div class="right" >
        <div class="personal_des Releasecont">
            <div class="head">
                <h1>我的收藏</h1>
            </div>

        </div>
        <div class="personal_des permessage">
            <div class="head">
                <ul class="tab_header messagehead">
                    <li class="active"><a href="{% url 'users:user_loveorg' %}">课程机构</a> </li>
                    <li><a href="{% url 'users:user_loveteacher' %}">授课教师 </a></li>
                    <li><a href="{% url 'users:user_lovecourse' %}">公开课程</a></li>
                </ul>
            </div>

            <div class="messagelist">
                {% for org in org_list %}
                <div class="messages butler_list company company-fav-box">
                    <dl class="des fr">
                        <dt>
                            <a href="{% url 'orgs:org_detail' org.id %}">
                                <img width="160" height="90" src="{{ MEDIA_URL }}{{ org.image }}"/>
                            </a>
                        </dt>

                        <dd>
                            <h1><a href="{% url 'orgs:org_detail' org.id %}">{{ org.name }}</a></h1>
                            <div class="pic fl" style="width:auto;">

                                <img src="{% static 'images/authentication.png' %}"/>

                                <img src="{% static 'images/gold.png' %}"/>
                            </div>
                            <span class="c8 clear">{{ org.address }}</span>
                            <div class="delete jsDeleteFav_org" data-favid="{{ org.id }}"></div>
                        </dd>
                    </dl>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}

{% block user %}{% endblock %}

{% block myjs1 %}
<script>
    // 页面加载完成
    $(function () {
        $('.delete').click(function () {
            {# prop()用来取元素自带属性的值或者设置值,attr()用来取元素自定义的属性的值或者设置值 #}
            var loveid = $(this).attr('data-favid');
            var lovetype = 1;  // 1表示机构类型
            var obj = $(this);
            $.ajax({
                type:'GET',
                url:'{% url 'operations:user_deletelove' %}',
                data:{
                    loveid:loveid,
                    lovetype:lovetype,
                },
                success:function (callback) {
                    if (callback.status == 'ok'){
                        alert(callback.msg);
                        {# window.location.reload();  // 取消收藏后页面刷新 #}
                        {# 拿到点击对象的祖先节点 当中有类名是des的祖先节点 然后在删除div 页面不刷新#}
                        obj.parents('.messages').remove();
                    } else{
                        alert(callback.msg);
                    }
                }
            })
        });
    })

</script>
{% endblock %}


